package test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * USER: lintc 【lintiancong@zhuojianchina.com】
 * DATE: 2017-08-09 17:16
 */
public class SomeEvent {

    private long time;

    private String event;

    public SomeEvent(long time, String event) {
        this.time = time;
        this.event = event;
    }

    public void doSomeThing() {
        System.out.println(event);
        while(time > 0){
            time--;
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (time <= 3) {
                System.out.println(event + " 即将结束: " + time);
            }
        }
    }

    public static void main(String[] args) {
        List<SomeEvent> list = new ArrayList<>();
        list.add(new SomeEvent(20, "敲代码"));
        list.add(new SomeEvent(5, "休息"));
        list.add(new SomeEvent(10, "敲代码"));
        list.add(new SomeEvent(5, "休息"));
        for (SomeEvent event : list) {
            event.doSomeThing();
        }
    }
}
